*** Settings ***
Library    Canoelibrary
Library    Real_Button
Library    Compare_Image
Library    ADBScreenControllerLibrary
Library    ocr
Library    Fault_Inject
Library    AndroidAudioPlayerLibrary
Library    flash
Library    ADBScreenshot
Library    ADBRecorderLibrary    output_dir=videos    device_id=your_device_id
Library    String
Library    AppiumLibrary    # 或 SeleniumLibrary，取决于你的测试环

*** Keywords ***
比较图像
    [Arguments]    ${image_path_a}    ${image_path_b}
    ${mse}    ${ssim}    Compare Images    ${image_path_a}    ${image_path_b}
    [Return]    ${mse}    ${ssim}

Get And Parse UI Tree
    [Documentation]    获取 UI 树并解析指定 resource-id 元素的坐标
    [Arguments]    ${resource_id}    ${ui_tree_file}=window_dump.xml
    Get UI Tree    ${ui_tree_file}
    ${coordinates}=    Parse UI Tree    ${ui_tree_file}    ${resource_id}
    [Return]    ${coordinates}

根据ID点击图标
    [Documentation]    根据 resource-id 查找元素并点击
    ${coords}=    Get And Parse UI Tree    com.example.app:id/button
    Click Element   ${coords[0]}    ${coords[1]}

根据坐标点击图标
    [Documentation]    根据 提供的坐标参数点击屏幕
    [Arguments]    ${x}    ${y}
    Click Element    ${x}    ${y}

在设备上播放语音文件
    [Arguments]    ${device_file_path}
    Play Audio File    ${device_file_path}

从图像中提取文字
    [Arguments]    ${image_path}    ${lang}=chi_sim    ${config}=None
    ${text}=    OCR From Image    ${image_path}    lang=${lang}    config=${config}
    [Return]    ${text}

滑屏
    [Arguments]    ${start_x}    ${start_y}    ${end_x}    ${end_y}    ${duration}=200
    Swipe Screen    ${start_x}    ${start_y}    ${end_x}    ${end_y}    ${duration}

ADB调用
    Run Adb Command

截全屏
    Take Full Screenshot

裁剪图片
    Crop Screenshot

本地获取图片
    Pull Screenshot

删除设备文件
    Delete File

二坐标截屏
    Take Partial Screenshot

拨打电话
    Call Number

屏幕点击序列
    [Arguments]    ${坐标列表}    ${循环次数}    ${延迟时间}
    @{坐标点}=    Split String    ${坐标列表}    sep=    maxsplit=0
    FOR    ${i}    IN RANGE    ${循环次数}
        FOR    ${point}    IN    @{坐标点}
            ${x}=    Get X Coordinate    ${point}
            ${y}=    Get Y Coordinate    ${point}
            Tap      ${x}    ${y}
            Sleep    ${延迟时间}
        END
    END

Get X Coordinate
    [Arguments]    ${point}
    ${parts}=    Split String    ${point}    sep=,    maxsplit=1
    [Return]    ${parts[0]}

Get Y Coordinate
    [Arguments]    ${point}
    ${parts}=    Split String    ${point}    sep=,    maxsplit=1
    [Return]    ${parts[1]}
开始录制
    Start Recording

结束录制
    Stop Recording

拉取视频到本地
    [Arguments]    ${filename}=recording.mp4
    Pull Video    ${filename}

删除本地视频
    [Arguments]    ${filename}=recording.mp4
    Delete Video On Device    ${filename}

重启
    Reboot Device
